﻿<!--
/*
 * (C) Copyright 2011 Adobe Systems Incorporated. All Rights Reserved.
 *
 * NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the 
 * terms of the Adobe license agreement accompanying it.  If you have received this file from a 
 * source other than Adobe, then your use, modification, or distribution of it requires the prior 
 * written permission of Adobe. 
 * THIS CODE AND INFORMATION IS PROVIDED "AS-IS" WITHOUT WARRANTY OF
 * ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 *
 *  THIS CODE IS NOT SUPPORTED BY Adobe Systems Incorporated.
 *
 */
-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>LiveAssistant Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style type="text/css">
td img {display: block;}body {
	background-color: #191919;
}
a:link {
	text-decoration: none;
	color: #F00;
}
a:hover {
	text-decoration: underline;
	color: #F00;
}
a:visited {
	text-decoration: none;
	color: #F00;
}
a:active {
	text-decoration: none;
	color: #F00;
}
.style22 {
	color: #666666;
}
.style23 {
	font-family: Arial, Helvetica, sans-serif; 
	font-size: 12px;
}
.style31 {
	font-family: "Arial";
	color: #999999;
	font-size: 12px;
	font-weight: bold;
}
.style34 {
	font-family: "Arial";
}
.style24 {	font-size: 11px;
	color: #999999;
	font-family: Arial, Helvetica, sans-serif;
}
.style62 {
	font-size: 12px; color: #999999; 
	font-family: "myriad Pro"; 
}
.style67 {
	font-family: "myriad Pro";
	color: #999999;
	font-size: 12px;
	font-weight: bold;
}
.style69 {
	font-family: "Arial";
	color: #999999;
	font-weight: bold;
}
.style1 {	
	font-family: Arial, Helvetica, sans-serif;
	color: #999999;
	font-size: 14px;
	font-weight: bold;
}
.style3 {
	font-family: "Arial";
	font-size: 12px;
	line-height: normal;
	height: 10px;
}
.style71 {
	font-family: "myriad Pro";
}
.style73 {
	font-family: Arial; 
	color: #999999; 
	font-size: 12px; 
	font-weight: bold; 
}
.style74 {
	font-size: 12px; 
	color: #999999; 
	font-family: Arial; 
}
.style75 {
	font-family: Arial;
	color: #CCC;
	font-size: 12px;
	font-weight: bold;
}
.style76 {
	font-size: 12px;
	font-family: Arial;
	color: #FF0000;
}
.style81 {
	font-family: Arial;
}
.style82 {
	color: #999999; 
	font-size: 12px;
}
.style83 {
	font-size: 12px; 
	font-weight: bold; 
	color: #999999;
}
</style>

<!-- functionality -->
<script type="text/javascript" src="scripts/swfobject.js"></script>
<script type="text/javascript" src="scripts/utf.js"></script>
    <script language="javascript">

		var queryParameters = new Array();
        var flashVars = "";
		var url = "";
		var output;
		var wsState = "idle";
		var websocket;
		var initload = true;
		var player;
		var rtmp_port = 1935;
	
  function onOpen(evt)
  {
    writeToScreen("websocket connected");
	wsState = "connected";
    doCmd("get_rtmp_port");
	doCmd("get_mic");
	doCmd("get_cam");
	doCmd("get_mic_vol");
  }

  function onClose(evt)
  {
    writeToScreen("DISCONNECTED");
	wsState = "idle";
  }
  
  function playRTMPStream(url){
  	document.getElementById('inputURL').value = url;
	queryParameters['source'] = url;
	initialize();
  }
  
  var wsResult = [
  	"MOV_START_SUC",
	"MOV_START_FAIL",
	"MOV_STOP_SUC",
	"MOV_STOP_FAIL",
	"MOV_PAUSE_SUC",
	"MOV_PAUSE_FAIL",
	"MOV_RESUME_SUC",
	"MOV_RESUME_FAIL",
	"MOV_SEEK_SUC",
	"MOV_SEEK_FAIL",
	"MOV_PROPERTY",
	"SS_START_SUC",
	"SS_START_FAIL",
	"SS_STOP_SUC",
	"SS_STOP_FAIL",
	"REC_START_SUC",
	"REC_START_FAIL",
	"REC_STOP_SUC",
	"REC_STOP_FAIL",
	"REC_PAUSE_SUC",
	"REC_PAUSE_FAIL",
	"REC_RESUME_SUC",
	"REC_RESUME_FAIL",
	"MOV_PLAY_FINISH",
	"MOV_VERSION",
	"SS_VERSION",
	"REC_VERSION",
	"MOV_SELECT_FILE_CANCEL",
	"QAV_LOGIN_SUC",
	"QAV_LOGIN_FAIL",
	"QAV_LOGOUT_SUC",
	"QAV_LOGOUT_FAIL",
	"QAV_ENTERROOM_SUC",
	"QAV_ENTERROOM_FAIL",
	"QAV_LEAVEROOM_SUC",
	"QAV_LEAVEROOM_FAIL",
	"QAV_OPEN_MIC_SUC",
	"QAV_OPEN_MIC_FAIL",
	"QAV_OPEN_MIC_NODEV",
	"QAV_CLOSE_MIC_SUC",
	"QAV_CLOSE_MIC_FAIL",
	"QAV_CLOSE_MIC_NODEV",
	"QAV_OPEN_PLAYER_SUC",
	"QAV_OPEN_PLAYER_FAIL",
	"QAV_OPEN_PLAYER_NODEV",
	"QAV_CLOSE_PLAYER_SUC",
	"QAV_CLOSE_PLAYER_FAIL",
	"QAV_CLOSE_PLAYER_NODEV",
	"QAV_MUTE_AUDIO_SUC",
	"QAV_MUTE_AUDIO_FAIL",
	"QAV_UNMUTE_AUDIO_SUC",
	"QAV_UNMUTE_AUDIO_FAIL",
	"REC_SAVE_FILE_CANCEL",
	"GET_MIC_SUC",
	"GET_MIC_FAIL",
	"DS_START_SUC",
	"DS_START_FAIL",
	"DS_STOP_SUC",
	"DS_STOP_FAIL",
	"AUD_START_SUC",
	"AUD_START_FAIL",
	"AUD_STOP_SUC",
	"AUD_STOP_FAIL",
	"AUD_DATA",
	"SS_DATA",
	"MOV_DATA",
	"PEN_START_SUC",
	"PEN_START_FAIL",
	"PEN_STOP_SUC",
	"PEN_STOP_FAIL",
	"PEN_VERSION",
    "QAV_DEVICE_SUC",
    "QAV_DEVICE_FAIL",
	"CBD_QUERY_SUC",
	"CBD_QUERY_FAIL",
	"CBD_GET_SUC",
	"CBD_GET_FAIL",
	"FILE_GET_SUC",
	"FILE_GET_FAIL",
	"FILE_SET_SUC",
	"FILE_SET_FAIL",
	"RESTART_SUC",
	"RESTART_FAIL",
	"GET_CAM_SUC",
	"GET_CAM_FAIL",
	"CAM_START_SUC",
	"CAM_START_FAIL",
	"CAM_STOP_SUC",
	"CAM_STOP_FAIL",
	"SWITCH_SCENE_SUC",
	"SWITCH_SCENE_FAIL",
	"PUSH_STREAM_FAIL",
	"SHOW_UI_SUC",
	"SET_VIDEO_PARAM_SUC",
	"SET_VIDEO_PARAM_FAIL",
	"GET_VIDEO_PARAM_SUC",
	"GET_VIDEO_PARAM_FAIL",
	"START_RECORD_SUC",
	"START_RECORD_FAIL",
	"STOP_RECORD_SUC",
	"STOP_RECORD_FAIL",
	"START_PUSH_SUC",
	"START_PUSH_FAIL",
	"STOP_PUSH_SUC",
	"STOP_PUSH_FAIL",
	"GET_RTMP_PORT_SUC",
	"GET_RTMP_PORT_FAIL",
	"SET_MIC_VOL_SUC",
	"SET_MIC_VOL_FAIL",
	"GET_MIC_VOL_SUC",
	"GET_MIC_VOL_FAIL",
	"RTMP_CONNECTING",
	"RTMP_CONNECT_SUC",
	"RTMP_CONNECT_FAIL",
	"RTMP_CONNECT_CLOSED"];
  
  function onMessage(evt)
  {
 	if(typeof(evt.data)=="string"){ 
	 writeToScreen('<span style="color: green;">receive string</span>');
	}
	else{ 
		writeToScreen('<span style="color: green;">receive binary</span>');
		var reader = new FileReader(); 
		reader.onload = function(evt){ 
			if(evt.target.readyState == FileReader.DONE){ 
				var dv = new DataView(evt.target.result); 
				writeToScreen('<span style="color: green;">receive string ' + dv.byteLength +'</span>');
				var result = dv.getUint16(0, true);
				var byte_order = dv.getUint8(2, true);
				var data_len = dv.getUint32(4, true);
				
				if( result >= 0 && result < wsResult.length ){
					var resultString = wsResult[result];
					writeToScreen('<span style="color: green;">result: ' + resultString + ' </span>');
				}
				else{
					writeToScreen('<span style="color: green;">result:  unknown result  </span>');
				}
				
				if(0 == result || 6 == result || 8 == result){//mov_start,mov_pause,mov_seek success
					playRTMPStream("rtmp://127.0.0.1:" + rtmp_port + "/live/ms");
				}
				else if(10 == result){//movie property
				   if(data_len > 7 * 4 + 8){
						var uint32params = new Uint32Array(evt.target.result, 8, 8);
						var info = "width:" + uint32params[0] + " height:" + uint32params[1];
						writeToScreen(info);
						info = "framerate:" + uint32params[2] + " duration:" + uint32params[3];
						writeToScreen(info);  
						
						document.getElementById("duration").value = parseInt(uint32params[3]);
						
                        info = "playpos:" + uint32params[4] + " filesize:" + uint32params[5];						
						writeToScreen(info);  
						var file_name_len = uint32params[6];
						var file_name = new Uint8Array(evt.target.result, 40 , file_name_len);
						var file_name_string = utf8to16(file_name);
						writeToScreen("filename:"+ file_name_string);
				   }
				}
				else if(11 == result){//ss_start success
					playRTMPStream("rtmp://127.0.0.1:" + rtmp_port + "/live/ss");
				}
				else if(24 <= result && 26 >= result){
				    if(data_len >= 4){
				        var version = dv.getUint32(8, true);
				        document.getElementById('ss_version_result').value = version.toString();
				        writeToScreen('<span style="color: green;">result: ' + version + ' </span>');
				    }
				}
				else if(55 == result){//ds_start success
					playRTMPStream("rtmp://127.0.0.1:" + rtmp_port + "/live/ds");
				}
				else if(59 == result){//as start success
				    playRTMPStream("rtmp://127.0.0.1:" + rtmp_port + "/live/as");
				}
				else if(result == 83){//get camera sucess
					if(data_len > 4){
						var cam_num = dv.getUint32(8, true);
						var offset = 12;
						var camSel = document.getElementById("cameras");
						camSel.options.length = 0;
						for(var i=0;i<cam_num; i++){
							var cam_name_len = dv.getUint32(offset, true);
							offset += 4;
							var cam_name = new Uint8Array(evt.target.result, offset , cam_name_len - 1);
							offset += cam_name_len;
							//var data_sting =  new TextDecoder("utf-8").decode(cam_name);
							var data_sting = utf8to16(cam_name);

							writeToScreen('<span style="color: green;">Camera: ' + i + " " + data_sting + ' </span>');
							var op = document.createElement("option");
							op.value = i;
							op.text = data_sting;
							camSel.add(op);
						}
					}
				}
				else if(53 == result){//get mic success
					if(data_len > 4){
						var mic_num = dv.getUint32(8, true);
						var offset = 12;
						var micSel = document.getElementById("mics");
						micSel.options.length = 0;
						for(var i=0;i<mic_num; i++){
							var mic_name_len = dv.getUint32(offset, true);
							offset += 4;
							var mic_name = new Uint8Array(evt.target.result, offset , mic_name_len - 1);
							offset += mic_name_len;
							//var data_sting =  new TextDecoder("utf-8").decode(mic_name);
							var data_sting = utf8to16(mic_name);
							writeToScreen('<span style="color: green;">MIC: ' + i + " " + data_sting + ' </span>');
							var op = document.createElement("option");
							op.value = i;
							op.text = data_sting;
							micSel.add(op);
						}
					}
				}
				else if(85 == result){//cam_share success
					playRTMPStream("rtmp://127.0.0.1:" + rtmp_port + "/live/cs");
				}
				else if(95 == result){//get_videoparam success
					var data = new Uint8Array(evt.target.result, 8, evt.target.result.byteLength - 8 -1);
					//var data_sting =  new TextDecoder("utf-8").decode(data);
					var data_sting = utf8to16(data);
					var input = document.getElementById('videoparam');
					input.value = data_sting;
					writeToScreen('<span style="color: green;">get_videoparam result: ' + data_sting + ' </span>');
				}
				else if(105 == result){//get_rtmp_port_success
				   	var data = new Uint8Array(evt.target.result, 8, evt.target.result.byteLength - 8 -1);
					//var data_sting =  new TextDecoder("utf-8").decode(data);
					var data_sting = utf8to16(data);
					var input = document.getElementById('rtmp_port');
					input.value = data_sting;
					rtmp_port = data_sting;
					writeToScreen('<span style="color: green;">get_rtmp_port result: ' + data_sting + ' </span>'); 
				}
				else if(109 == result){//get_mic_vol success
					var data = new Uint8Array(evt.target.result, 8, evt.target.result.byteLength - 8 -1);
					//var data_sting =  new TextDecoder("utf-8").decode(data);
					var data_sting = utf8to16(data);
					var input = document.getElementById('mic_vol');
					input.value = data_sting;
					writeToScreen('<span style="color: green;">get_mic_vol result: ' + data_sting + ' </span>'); 
				}
				else if(111 <=result && 114>= result){
					var data = new Uint8Array(evt.target.result, 8, evt.target.result.byteLength - 8);
				    var url =  utf8to16(data);
					writeToScreen('<span style="color: green;">url: ' + url + ' </span>'); 
				}
				else{
				    var data = new Uint8Array(evt.target.result, 8, evt.target.result.byteLength - 8);
					//var data_sting =  new TextDecoder("utf-8").decode(data);
					var data_sting = utf8to16(data);
					writeToScreen('<span style="color: green;">url: ' + data_sting + ' </span>');
				}
			}
		}
		reader.readAsArrayBuffer(evt.data); 
	}
   }

  function onError(evt)
  {
    writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
  }

  function doSendWSCmd(wsCmd)
  {
   if(wsState != "connected"){
		writeToScreen("websocket isn't connected,please connect first!");
		return;
   }
  
    writeToScreen("Send: " + wsCmd.name);

	var cmd_buf_len = 2 + 1*2 + 4 + wsCmd.data_len;
	var buffer = new ArrayBuffer(cmd_buf_len);
	var cmd = new Uint16Array(buffer, 0, 1);
	var byte_order = new Uint8Array(buffer, 2, 1);
	var data_len = new Uint32Array(buffer, 4, 1);
	
	cmd[0] = wsCmd.type;
	byte_order[0] = 0;
	data_len[0] = wsCmd.data_len;
	
	if(wsCmd.data_len > 0){
		var data_buf = new Uint8Array(buffer, 8, wsCmd.data_len);
		for(var i=0;i< wsCmd.data_len; i++){
			data_buf[i] = wsCmd.data[i];
		}
	}

    websocket.send(buffer);
  }
  
  	function onTestClick(obj)
	{
		doCmd(obj.id);
	}
	
	function doCmd(cmdName)
	{
			writeToScreen(cmdName);
			var cmd = new Object();
			cmd.data_len = 0;
			cmd.data = "";
			cmd.name = cmdName;
			
			if(cmdName == "mov_start"){
				cmd.type = 1;
			}
			else if(cmdName == "mov_stop"){
				cmd.type = 2;
			}
			else if(cmdName == "mov_pause"){
			    cmd.type = 3;
				var pos = document.getElementById("mov_pos").value;
				if(pos.length > 0){
				   cmd.data_len = 4;
				   var buffer = new ArrayBuffer(cmd.data_len);
					var Uint32param = new Uint32Array(buffer, 0, 1);
					Uint32param[0] = parseInt(pos);
					cmd.data = new Uint8Array(buffer, 0, 4);
				}
			}
			else if(cmdName == "mov_resume"){
			    cmd.type = 4;
			}
			else if(cmdName == "mov_seek"){
			    cmd.type = 5;
				var pos = document.getElementById("mov_pos").value;
				if(pos.length > 0){
				   cmd.data_len = 4;
				   var buffer = new ArrayBuffer(cmd.data_len);
					var Uint32param = new Uint32Array(buffer, 0, 1);
					Uint32param[0] = parseInt(pos);
					cmd.data = new Uint8Array(buffer, 0, 4);
				}
			}
			else if(cmdName == "ss_start"){
				cmd.type = 6;
				var param = document.getElementById("ss_start_input");
				//cmd.data = new TextEncoder("utf-8").encode(param.value);
				cmd.data = utf16to8(param.value);
				cmd.data_len = cmd.data.length;
			}
			else if(cmdName == "ss_stop"){
			    cmd.type = 7;
			}
			else if(cmdName == "ss_version"){
			    cmd.type = 14;
			}
			else if(cmdName == "get_mic"){
				cmd.type = 26;
			}
			else if(cmdName == "ds_start"){
				cmd.type = 27;
				cmd.data_len = 4*6 + 256 + 256;
				var buffer = new ArrayBuffer(cmd.data_len);
				var int32param = new Uint32Array(buffer, 0, 6);
				var coordstr = document.getElementById("ds_start_coord").value;
				var coordarray = coordstr.split(",");
				if(coordarray.length == 4){
					int32param[0] = parseInt(coordarray[0]);
					int32param[1] = parseInt(coordarray[1]);
					int32param[2] = parseInt(coordarray[2]);
					int32param[3] = parseInt(coordarray[3]);
				}
				else
				{
				   //promopt error parameter
				   return;//
				}
				
				var window_name_buffer = new Uint8Array(buffer, 24, 256);
				var window_name = document.getElementById("ds_start_window_name").value;
				//var window_name_array = new TextEncoder("utf-8").encode(window_name);
				var window_name_array = utf16to8(window_name);
				for(var i=0;i< window_name_array.length; i++){
				   window_name_buffer[i] = window_name_array[i];
				}
				
				int32param[4] = window_name_array.length;
				int32param[5] = 0;
				
				var url_name = new Uint8Array(buffer, 24 + 256, 256);//todo: set push url
				cmd.data = new Uint8Array(buffer, 0, cmd.data_len);
				doSendWSCmd(cmd);
				return;
			}
			else if(cmdName == "ds_stop"){
				cmd.type = 28;
			}
			else if(cmdName == "aud_start"){
				cmd.type = 29;
				cmd.data_len = 4 + 4 + 256 + 256;
				var buffer = new ArrayBuffer(cmd.data_len);
				var mic_name_len = new Uint32Array(buffer, 0, 1);
				var micSel = document.getElementById("mics");
				var index = micSel.selectedIndex;
				var sel_mic_name = micSel.options[index].text;
				mic_name_len[0] = sel_mic_name.length;
				var urlname_len = new Uint32Array(buffer, 4, 1);
				urlname_len[0] = 0;
				var mic_name = new Uint8Array(buffer, 8, 256);
				//var mic_name_array = new TextEncoder("utf-8").encode(sel_mic_name);
				var mic_name_array = utf16to8(sel_mic_name);
				for(var i=0;i< mic_name_array.length; i++){
				   mic_name[i] = mic_name_array[i];
				}
				var url_name = new Uint8Array(buffer, 8 + 256, 256);//todo: set push url
				cmd.data = new Uint8Array(buffer, 0, cmd.data_len);
				doSendWSCmd(cmd);
				return;
			}
			else if(cmdName == "aud_stop"){
				cmd.type = 30;
			}
			else if(cmdName == "get_cam"){
				cmd.type = 41;
			}
			else if(cmdName == "cam_start"){
				cmd.type = 42;
				cmd.data_len = 4 + 4 + 256 + 256;
				var buffer = new ArrayBuffer(cmd.data_len);
				var cam_name_len = new Uint32Array(buffer, 0, 1);
				var camSel = document.getElementById("cameras");
				var index = camSel.selectedIndex;
				var sel_cam_name = camSel.options[index].text;
				cam_name_len[0] = sel_cam_name.length;
				var urlname_len = new Uint32Array(buffer, 4, 1);
				urlname_len[0] = 0;
				var cam_name = new Uint8Array(buffer, 8, 256);
				//var cam_name_array = new TextEncoder("utf-8").encode(sel_cam_name);
				var cam_name_array = utf16to8(sel_cam_name);
				for(var i=0;i< cam_name_array.length; i++){
				   cam_name[i] = cam_name_array[i];
				}
				var url_name = new Uint8Array(buffer, 8 + 256, 256);//todo: set push url
				cmd.data = new Uint8Array(buffer, 0, cmd.data_len);
				doSendWSCmd(cmd);
				return;
			}
			else if(cmdName == "cam_stop"){
				cmd.type = 43;
			}
			else if(cmdName == "set_videoparam"){
				cmd.type = 46;
				var param = document.getElementById("videoparam");
				//cmd.data = new TextEncoder("utf-8").encode(param.value);
				cmd.data = utf16to8(param.value);
				cmd.data_len = cmd.data.length;
			}
			else if(cmdName == "get_videoparam"){
			    cmd.type = 47;
				var sourceSel = document.getElementById("sources");
				var index = sourceSel.selectedIndex;
				//cmd.data = new TextEncoder("utf-8").encode(sourceSel.options[index].text);
				cmd.data = utf16to8(sourceSel.options[index].text);
				cmd.data_len = cmd.data.length;
			}
			else if(cmdName == "start_record"){
				cmd.type = 48;
				var param = document.getElementById("start_record_input");
				//cmd.data = new TextEncoder("utf-8").encode(param.value);
				cmd.data = utf16to8(param.value);
				cmd.data_len = cmd.data.length;
			}
			else if(cmdName == "stop_record"){
				cmd.type = 49;
				var param = document.getElementById("start_record_input");
				cmd.data = utf16to8(param.value);
				cmd.data_len = cmd.data.length;
			}
			else if(cmdName == "start_push"){
				cmd.type = 50;
				var param = document.getElementById("start_push_input");
				cmd.data = utf16to8(param.value);
				cmd.data_len = cmd.data.length;
			}
			else if(cmdName == "stop_push"){
				cmd.type = 51;
				var param = document.getElementById("start_push_input");
				cmd.data = utf16to8(param.value);
				cmd.data_len = cmd.data.length;
			}
			else if(cmdName == "get_rtmp_port"){
				cmd.type = 52;
			}
			else if(cmdName == "set_mic_vol"){
			    cmd.type = 53;
				var param = document.getElementById("mic_vol");
				cmd.data = utf16to8(param.value);
				cmd.data_len = cmd.data.length;
			}
			else if(cmdName == "get_mic_vol"){
			    cmd.type = 54;
			}
			
			doSendWSCmd(cmd);
	}

  function writeToScreen(message)
  {
    var pre = document.createElement("p");
    pre.style.wordWrap = "break-word";
	pre.className = "style75";
    pre.innerHTML = message;
    output.appendChild(pre);
  }
  
function getExplorerTitle() {
	var explorer = window.navigator.userAgent.toLowerCase();
	//ie 
	if (explorer.indexOf("msie") >= 0 || explorer.indexOf("trident") >0 ) {
		return "Internet Explorer";
	}
	//firefox 
	else if (explorer.indexOf("firefox") >= 0) {
		return "Mozilla Firefox";
	}
	//Chrome
	else if (explorer.indexOf("chrome") >= 0) {
		return "Google Chrome";
	}
	//Opera
	else if (explorer.indexOf("opera") >= 0) {
		return "Opera";
	}
	//Safari
	else if (explorer.indexOf("Safari") >= 0) {
		return "";
	}
	return "";
}
        
        window.onload = function ()
        {
			output = document.getElementById("output");
			
			document.getElementById( 'websocketURL' ).value = "ws://127.0.0.1:6080";
		
 			document.getElementById( 'inputURL' ).value = queryParameters['source'];
			
			var default_ss_start_param = "0,0," + window.screen.width + "," + window.screen.height;
			document.getElementById('ss_start_input').value = default_ss_start_param;
			
			var window_name =  document.title + " - " + getExplorerTitle();
			document.getElementById('ds_start_window_name').value = window_name;

			var default_ss_start_pos = "0,0," + window.screen.width + "," + window.screen.height;
			document.getElementById('ds_start_coord').value = default_ss_start_pos; 

		}
		
	    function onJavaScriptBridgeCreated(id){  
			player = document.getElementById(id);  
		}  

        function initialize() 
        {
			function getUrlParam( name )
			{
				  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
				  var regexS = "[\\?&]"+name+"=([^&#]*)";
				  var regex = new RegExp( regexS );
				  var results = regex.exec( window.location.href );
				  if( results == null )
						return "";
				  else
						return unescape( results[1] );
			}

			if(initload == true){
			queryParameters['source'] = getUrlParam('source');
			queryParameters['type'] = getUrlParam('type');
			queryParameters['idx'] = getUrlParam('idx');
			initload = false;
			}
			else{
			   flashVars = "";
			   swfobject.removeSWF("StrobeMediaPlayback");
			   var v = document.getElementById("flashContent");
			   if(v == null){
			      var flashContentParent = document.getElementById("flashContentParent");
				  if(flashContentParent){
				     flashContentParent.innerHTML = "<div id=\"flashContent\"></div>";
				  }
			   }
			   queryParameters['type'] = "live";
			}

			if( queryParameters['source'] == "" )
				queryParameters['source'] = "rtmp://localhost/live/ss";
			
			if( queryParameters['type'] == "" )
				queryParameters['type'] = "live";
				
			if( queryParameters['idx'] == "" )
				queryParameters['idx'] = "2";
			

			flashVars += "&src=";
            flashVars += queryParameters['source'];

            flashVars += "&autoHideControlBar=";
            flashVars += unescape("true");

            flashVars += "&streamType=";
            flashVars += queryParameters['type'];

            flashVars += "&autoPlay=";
            flashVars += unescape("true");
		  
		  flashVars += "&verbose=";
		  flashVars += "true";

            var soFlashVars = {
                src: queryParameters['source'],
			 streamType: queryParameters['type'],
                autoPlay: "true",
                controlBarAutoHide: "true",
                controlBarPosition: "bottom",
				liveBufferTime : "1", 
				liveDynamicStreamingBufferTime :"0",
				bufferTime :"0",
				initialBufferTime :"0",
				javascriptCallbackFunction: "onJavaScriptBridgeCreated" 
            };

 			<!-- For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. -->
		var swfVersionStr = "10.3.0";
		<!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. -->
		var xiSwfUrlStr = "swfs/playerProductInstall.swf";
		var params = {};
		params.quality = "high";
		params.bgcolor = "#000000";
		params.allowscriptaccess = "sameDomain";
		params.allowfullscreen = "true";           
		var attributes = {};
		attributes.id = "StrobeMediaPlayback";
		attributes.name = "StrobeMediaPlayback";
		attributes.align = "middle";
		swfobject.embedSWF("swfs/StrobeMediaPlayback.swf", "flashContent", "640", "377", swfVersionStr, xiSwfUrlStr, soFlashVars, params, attributes);
		<!-- JavaScript enabled so display the flashContent div in case it is not replaced with a swf object. -->
		if(initload == true){
			swfobject.createCSS("#flashContent", "display:block;text-align:left;");
		}
        } 

		function playStream()
		{
			queryParameters['source'] = document.getElementById('inputURL').value;
			initialize();
		}

		function connectLiveServ()
		{
			var url = document.getElementById('websocketURL').value;
		
			if( wsState == "idle"){
				wsState = "connecting";
				writeToScreen("connecting " + url);
			    websocket = new WebSocket(url);
				websocket.onopen = function(evt) { onOpen(evt) };
				websocket.onclose = function(evt) { onClose(evt) };
				websocket.onmessage = function(evt) { onMessage(evt) };
				websocket.onerror = function(evt) { onError(evt) };
			}
		}
		
		function disconnectLiveServ()
		{
			if( wsState == "connected"){
				wsState = "closing";
			    websocket.close();
			}
		}
		
		function clearOutput()
		{
			output.innerHTML = "";
		}
		
		initialize();

    </script>

</head>
<body>
<table>
<tr>
         <td colspan="4" align="left" bgcolor="#191919"><img src="images/canvas.gif" alt="" name="index_r4_c3" width="1200" height="39" border="0" id="index_r4_c3" /></td>
     </tr>
<tr>
   <td colspan="4" align="left" bgcolor="#191919">
             <table width="100%" border="0" cellspacing="10" cellpadding="0">
                 <tr>
                     <td >
                         <table width="65%" border="0" cellspacing="0" cellpadding="0">
                             <tr>
                                 <!-- Here goes the StrobeMediaPlayback -->
                                 <td valign="top">
                                     <!-- SWFObject's dynamic embed method replaces this alternative HTML content with Flash content when enough
                                         JavaScript and Flash plug-in support is available. The div is initially hidden so that it doesn't show
                                         when JavaScript is disabled.
                                    -->
                                     <div id="flashContentParent">
                                         <div id="flashContent">
                                             <p>To view this page ensure that Adobe Flash Player version 10.3.0 or greater is installed.</p>
                                             <script type="text/javascript">

				var pageHost = ((document.location.protocol == "https:") ? "https://" :	"http://");
				document.write("<a href='http://www.adobe.com/go/getflashplayer'><img src='"
								+ pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>" );
                                             </script>
                                         </div>
                                     </div>
                                     <noscript>
                                         <a href="http://www.adobe.com/go/getflashplayer/" style="color:black"><img src="images/ERROR_getFlashPlayer.gif" width="640" height="377" /></a>
                                     </noscript>
                                 </td>
                             </tr>
                         </table>
                     </td>
                     <td>
                         <table width="100" border="0" cellspacing="0" cellpadding="0">
                             <tr>
                                 <td><span class="style75">click on following buttons to test liveserver</span></td>
                                 <td>&nbsp;</td>
                                 <td>&nbsp;</td>
                             </tr>
                             <tr>
                                 <td background="images/upperright_03.gif">
                                     <table border="0" cellspacing="4" cellpadding="0">
                                         <tr>
                                             <td colspan="1"><img src="images/spacer.gif" width="5" height="10" /></td>
                                             <td colspan="2"><button type="button" id="get_rtmp_port" onclick="onTestClick(this)">get_rtmp_port</button></td>
                                             <td colspan="1"><input id="rtmp_port" readonly="readonly" size="10" /></td>
                                             <td colspan="2" align="center"><button type="button" id="ss_version" onclick="onTestClick(this)">ss_version</button></td>
                                             <td colspan="1"><input id="ss_version_result" readonly="readonly" size="10"/></td>
                                         </tr>
                                         <tr>
                                             <td colspan="1"><img src="images/spacer.gif" width="5" height="10" /></td>
                                             <td colspan="2"><button type="button" id="ss_start" onclick="onTestClick(this)">ss_start</button></td>
                                             <td colspan="4"><input id="ss_start_input" size="45" /></td>
                                             <td colspan="2"><button type="button" id="ss_stop" onclick="javascript:onTestClick(this);">ss_stop</button></td>
                                         </tr>
                                         <tr>
                                             <td colspan="1"><img src="images/spacer.gif" width="5" height="10" /></td>
                                             <td colspan="2"><button type="button" id="ds_start" onclick="javascript:onTestClick(this);">ds_start</button></td>
                                             <td colspan="4"><input id="ds_start_coord" size="45" /><input id="ds_start_window_name" size="45" /></td>
                                             <td colspan="2"><button type="button" id="ds_stop" onclick="javascript:onTestClick(this);">ds_stop</button></td>
                                         </tr>
                                         <tr>
                                             <td colspan="1"><img src="images/spacer.gif" width="5" height="10" /></td>
                                             <td colspan="2"><button type="button" id="get_mic" onclick="javascript:onTestClick(this);">get_mic</button></td>
                                             <td colspan="4">
                                                 <img src="images/spacer.gif" width="5" height="10" />
                                                 <select id="mics" name="mics"/>
                                             </td>
                                         </tr>
                                         <tr>
                                             <td colspan="1"><img src="images/spacer.gif" width="5" height="10" /></td>
                                             <td colspan="2"><button type="button" id="aud_start" onclick="javascript:onTestClick(this);">aud_start</button></td>
                                             <td colspan="2"><button type="button" id="aud_stop" onclick="javascript:onTestClick(this);">aud_stop</button></td>
                                             <td colspan="1" align="center"><button type="button" id="get_mic_vol" onclick="javascript:onTestClick(this);">get_mic_vol</button></td>
                                             <td colspan="1"><input id="mic_vol" size="10" /></td>
                                             <td colspan="1"><button type="button" id="set_mic_vol" onclick="javascript:onTestClick(this);">set_mic_vol</button></td>
                                         </tr>
                                         <tr>
                                             <td colspan="1"><img src="images/spacer.gif" width="5" height="10" /></td>
                                             <td colspan="2"><button type="button" id="mov_start" onclick="javascript:onTestClick(this);">mov_start</button></td>
                                             <td colspan="2"> <input id="duration" readonly="readonly" size="10" /></td>
                                             <td colspan="1" align="center"><button type="button" id="mov_stop" onclick="javascript:onTestClick(this);">mov_stop</button></td>
                                         </tr>
                                         <tr>
                                             <td colspan="1"><img src="images/spacer.gif" width="5" height="10" /></td>
                                             <td colspan="2"><button type="button" id="mov_seek" onclick="javascript:onTestClick(this);">mov_seek</button></td>
                                             <td colspan="2"><input id="mov_pos" size="10" /></td>
                                             <td colspan="1" align="center"><button type="button" id="mov_pause" onclick="javascript:onTestClick(this);">mov_pause</button></td>
                                            <td colspan="1"><button type="button" id="mov_resume" onclick="javascript:onTestClick(this);">mov_resume</button></td>
                                         </tr>
                                         <tr>
                                             <td colspan="1"><img src="images/spacer.gif" width="5" height="10" /></td>
                                             <td colspan="2"><button type="button" id="get_cam" onclick="javascript:onTestClick(this);">get_cam</button></td>
                                             <td colspan="3">
                                                 <img src="images/spacer.gif" width="5" height="10" />
                                                 <select width="300" id="cameras" name="cameras" />
                                             </td>
                                             <td colspan="1"><button type="button" id="cam_start" onclick="javascript:onTestClick(this);">cam_start</button></td>
                                             <td colspan="1"><button type="button" id="cam_stop" onclick="javascript:onTestClick(this);">cam_stop</button></td>
                                         </tr>
                                         <tr>
                                             <td colspan="1"><img src="images/spacer.gif" width="5" height="10" /></td>
                                             <td colspan="2"><button type="button" id="start_push" onclick="javascript:onTestClick(this);">start_push</button></td>
                                             <td colspan="4">
                                                 <input id="start_push_input" size="50" list="start_push_sample_list" /><datalist id="start_push_sample_list">
                                                     <option value="0 video=scr audio=mic rtmp://127.0.0.1/live/0"></option>
                                                     <option value="1 video=doc audio=mic rtmp://127.0.0.1/live/1"></option>
                                                     <option value="2 video=cam audio=mic rtmp://127.0.0.1/live/2"></option>
                                                     <option value="3 video=mov audio=mov rtmp://127.0.0.1/live/3"></option>
                                                     <option value="4 video=non audio=mov rtmp://127.0.0.1/live/4"></option>
                                                     <option value="5 video=doc audio=non rtmp://127.0.0.1/live/5"></option>
                                                     <option value="6 video=doc audio=mov rtmp://127.0.0.1/live/6"></option>
                                                 </datalist>
                                             </td>
                                             <td colspan="2"><button type="button" id="stop_push" onclick="javascript:onTestClick(this);">stop_push</button></td>
                                         </tr>
                                         <tr>
                                             <td colspan="1"><img src="images/spacer.gif" width="5" height="10" /></td>
                                             <td colspan="2"><button type="button" id="start_record" onclick="javascript:onTestClick(this);">start_record</button></td>
                                             <td colspan="4">
                                                 <input id="start_record_input" size="50" list="start_record_sample_list" />
                                                 <datalist id="start_record_sample_list">
                                                     <option value="0 video=scr audio=mic" />
                                                     <option value="1 video=doc audio=mic" />
                                                     <option value="2 video=cam audio=mic" />
                                                     <option value="3 video=mov audio=mov" />
                                                 </datalist>
                                             </td>
                                             <td colspan="2"><button type="button" id="stop_record" onclick="javascript:onTestClick(this);">stop_record</button></td>
                                         </tr>
                                         <tr>
                                             <td colspan="1"><img src="images/spacer.gif" width="5" height="10" /></td>
                                             <td colspan="2"><button type="button" id="get_videoparam" onclick="javascript:onTestClick(this);">get_videoparam</button></td>
                                             <td colspan="1" align="center">
                                                 <select id="sources" name="sources">
                                                     <option value="scr">scr</option>
                                                     <option value="doc">doc</option>
                                                     <option value="mov">mov</option>
                                                     <option value="cam">cam</option>
                                                 </select>
                                             </td>
                                             <td colspan="3"><input id="videoparam" size="36" /></td>
                                             <td colspan="2"><button type="button" id="set_videoparam" onclick="javascript:onTestClick(this);">set_videoparam</button></td>
                                         </tr>
                                     </table>
                                 </td>
                             </tr>



                         </table>
                     </td>
                 </tr>
             </table>
  </td>
</tr>
<tr>
    <td colspan="3" valign="top" bgcolor="#191919"><table width="100" border="0" align="left" cellpadding="0" cellspacing="0">
        <tr>
          <td colspan="3" valign="top"><img src="images/spacer.gif" width="55" height="10" /></td>
        </tr>
        <tr>
          <td colspan="3" valign="top"><table width="87%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><span class="style69">Play RTMP stream</span></td>
            </tr>
            <tr>
              <td bgcolor="#666666"><img src="images/spacer.gif" width="5" height="3" /></td>
            </tr>
            <tr>
              <td><img src="images/spacer.gif" width="55" height="10" /></td>
            </tr>
            <tr>
              <td><table width="1000" border="0" align="left" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="8%"><table width="86" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td align="left"><span class="style73">STREAM URL:</span></td>
                    </tr>
                  </table></td>
                  <td align="left"></td>
                  <td align="left"><input name="inputURL" type="text" id="inputURL" size="80" maxlength="80" /></td>
                  <td width="42%" align="left"><table width="100" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="5%" align="left"><img src="images/spacer.gif" width="5" height="10" /></td>
                      <td width="5%" align="left"><img src="images/spacer.gif" width="5" height="10" /></td>
                      <td width="27%" align="left"><a id="playBtn" onclick="javascript:playStream();"><img src="images/playstream_10.gif" width="104" height="25" /></a></td>
                      <td align="left">&nbsp;</td>
                    </tr>
                  </table></td>
                  </tr>
                  <td colspan="4">&nbsp;</td>
                </tr>
              </table></td>
            </tr>
          </table></td>
 </tr>
<tr>
   <td colspan="3" valign="top">
    <table width="87%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><span class="style69">Connect Xuedianyun LiveServer</span></td>
            </tr>
            <tr>
              <td bgcolor="#666666"><img src="images/spacer.gif" width="5" height="3" /></td>
            </tr>
            
            <tr>
              <td><img src="images/spacer.gif" width="55" height="10" /></td>
            </tr>
            <tr>
              <td><table width="1000" border="0" align="left" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="8%"><table width="100" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td align="left"><span class="style73">Websocket URL:</span></td>
                    </tr>
                  </table></td>
                  <td align="left"></td>
                  <td align="left"><input name="websocketURL" type="text" id="websocketURL" size="80" maxlength="80" /></td>
                  <td width="42%" align="left"><table width="100" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                  <td width="2%" align="left"><img src="images/spacer.gif" width="5" height="10" /></td>
                      <td width="27%" align="left"><a id="connectBtn" onclick="javascript:connectLiveServ();"><img src="images/connect.gif" width="104" height="25" /></a></td>
                      <td align="left">&nbsp;</td>
                      <td width="27%" align="left"><a id="disconnectBtn" onclick="javascript:disconnectLiveServ();"><img src="images/disconnect.gif" width="104" height="25" />  
					  <td><img src="images/spacer.gif" width="50" height="10" /></td>
                      <td width="27%" align="left"><a id="clearBtn" onclick="javascript:clearOutput();"><img src="images/clear.gif" width="104" height="25" /></a></td>
                    </tr>
                  </table></td>
                  </tr>
              </table></td>
            </tr>
          </table>
   </td>
</tr>
</table>
<div id = output />
</body>
</html>

